<template>
	<view>
		<u-empty v-if="myneedlist.length===0" text="需求为空" mode="order" class="needisempty" iconSize="240rpx" font-size="40rpx">
		</u-empty>
		<!-- 管理按钮 -->
		<view class="managebutton" @click="show_popup()" v-if="myneedlist.length!=0"
			:style="{'color':(showpopup?'rgba(255, 87, 51, 1)':'rgba(112, 112, 112, 1)')}">{{showpopup?'完成':'管理'}}
		</view>
		<!-- 需求列表 -->
		<view class="myneedicardlist" v-if="myneedlist.length!=0">
			<view class="myneedicard" v-for="(item,index) in myneedlist" :key='index'>
				<view class="meedicardmargin">
					<view class="needicardtime">{{item.createTime}}</view>
					<view class="thistimeicard" :key="needindex">
						<view class="needicard" @click="goto()">
							<needcard :needcardall="item"></needcard>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-if="showpopup" class="delete" style="z-index: 999;">
			<u-icon :name="chooseall?'heart-fill':'heart'" size="40" class="manageicon" label="全选"
				style="width: 480rpx;margin-left: 30rpx;" @click="icardchooseall()"
				:style="{'color':(chooseall?'rgba(255, 87, 51, 1)':'rgba(112, 112, 112, 1)')}"></u-icon>
			<button class="deletebutton">删除</button>
		</view>
		<u-back-top :scroll-top="scrollTop" mode="square" tips="顶部"></u-back-top>
		<!-- 底部适配 -->
		<view class="adaptation"></view>
	</view>
</template>

<script>
	import needcard from '../../components/needcard/needcard.vue';
	export default {
		components: {
			needcard
		},
		data() {
			return {
				chooseall: false,
				scrollTop: 0,
				showpopup: false,
				myneedlist: []
			}
		},
		methods: {
			icardchooseall() { //点击选择
				this.chooseall = !this.chooseall;
			},
			show_popup() { //显示管理界面
				this.showpopup = !this.showpopup;
				// console.log(this.showpopup);
			},
			goto(){
				let urlstr = '../sends/sends_need?demandUuid='+this.on_saleitem.demandUuid
								+'&demandVarieties='+this.on_saleitem.demandVarieties
								+'&demandType='+this.on_saleitem.demandType
								+'&demandKilogram='+this.on_saleitem.demandKilogram
								+'&demandPrice='+this.on_saleitem.demandPrice
								+'&remarks='+this.on_saleitem.remarks
								+'&deadline='+this.on_saleitem.deadline
								// +'&demandMainImgUrl='+this.on_saleitem.demandMainImgUrl
				uni.navigateTo({
					url: urlstr,
					animationType: 'slide-in-right',
					animationDuration: 1000
				
				})
			},
			getmyneed() {
				this.$myRequest({
					url: '/demand/getMyPublishDemand',
					method: 'POST'
				}).then((res) => {
					if (res.data.code == 200) {
						let list = res.data.data;
						for (let i = 0; i < list.length; i++) {
							// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
							let item = JSON.parse(JSON.stringify(list[i]))
							// console.log(item)
							this.myneedlist.push(item);
						}
						// console.log(this.myneedlist);
					}
				})
				// console.log(this.myneedlist)
			}
		},
		onLoad() {
			this.getmyneed();
		},
		onPageScroll(e) { //生命周期函数
			this.scrollTop = e.scrollTop

		}
	}
</script>

<style>
	@import url("myneed.css");
</style>
